﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Baimasoft.Manage.SqlServerDAL;
using HsTec.Mobile.Green.Util;

public partial class Plan_Indicators : System.Web.UI.Page
{
    Param MyP = new Param();
    Dictionary<string, string> dic = new Dictionary<string, string>();
    public string sYearsTitle = String.Empty;
    public string colNum = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        GetExportList(sltStartYear.Value, sltEndYear.Value, 1);
    }
    private void GetExportList(string sStartYears, string sEndYears, int iType)
    {
        String sTD = String.Empty;
        //1.获取需要的数据
        DataView mydv = new DataView();
        string mysql = " SELECT RTRIM(b.name) AS colname, CASE WHEN h.id IS NOT NULL " +
                           "       THEN 'PK' ELSE '' END AS primarykey, type_name(b.xusertype) " +
                           "       + CASE WHEN b.colstat & 1 = 1 THEN '[ID(' + CONVERT(varchar, ident_seed(a.name)) " +
                           "       + ',' + CONVERT(varchar, ident_incr(a.name)) + ')]' ELSE '' END AS type, b.length, " +
                           "       CASE b.isnullable WHEN 0 THEN 'N' ELSE 'Y' END AS isnull, ISNULL(e.text, '') " +
                           "       AS [default], ISNULL(c.[value], '') AS descript " +
                           " FROM (SELECT g.id, g.colid " +
                           "         FROM sysindexes f, sysindexkeys g " +
                           "         WHERE f.id = g.id AND f.indid = g.indid AND f.indid > 0 AND f.indid < 255 AND " +
                           "               (f.status & 2048) <> 0) h RIGHT OUTER JOIN " +
                           "       syscolumns b INNER JOIN " +
                           "       sysobjects a ON b.id = a.id LEFT OUTER JOIN " +
                           "       sys.extended_properties c ON b.id = c.major_id AND b.colid = c.minor_id LEFT OUTER JOIN " +
                           "       syscomments e ON b.cdefault = e.id ON h.id = b.id AND h.colid = b.colid " +
                           " WHERE (a.id = OBJECT_ID('tb_Plan')) AND b.name not in ('P_ID','Area_ID','Years')" +
                           " ORDER BY b.colid";
        DataView dvField = SQLHelper.ExecuteDataView(mysql);
        string sField = String.Empty;
        for (int i = 92; i <= 108; i++)
        {
            sField += sField == "" ? "" + dvField[i]["colname"] : "," + dvField[i]["colname"];
        }
        mydv = SQLHelper.ExecuteDataView("select " + sField + ",years from tb_Plan where years>='" + sStartYears + "' and years<='" + sEndYears + "'");
        for (int i = 0; i < mydv.Count; i++)
        {
            sYearsTitle += "<td width='79'><div align='center' style='text-align: center'><strong>" + mydv[i]["years"].ToString() + "年</strong></div></td>";
        }
        //2.填充数值
        if (mydv.Count > 0)
        {
            DataTable dt = mydv.Table;
            for (int i = 0, j = 1; i < dt.Columns.Count; i++, j++)
            {
                sTD = String.Empty;
                for (int k = 0; k < dt.Rows.Count; k++)
                {
                    sTD += "<td>" + mydv[0][i] + "</td>";
                }
                Label lbl = (Label)this.FindControl("Label" + j);
                if (lbl != null)
                    lbl.Text = sTD;
            }
        }
        colNum = (mydv.Count + 4).ToString();
    }
}
